public class Algorithms {
    public static double degree(int i, boolean[][] matrix) {
   	 int length = matrix[0].length;
   	 int links = 0;
   	 double result;

   	 for (int j = 0; j < length; j++) {
   		 if (matrix[i][j] == true) {
   			 links++;
   		 }
   	 }
   	 result = (double) links / ((double) length - 1);
   	 return result;
    }

    public static double proximity(int i, boolean[][] matrix) {
   	 int length = matrix[0].length;
   	 boolean alreadyVisited[] = new boolean[length];
   	 boolean newAlreadyVisited[] = new boolean[length];
   	 int noIteration = 1;
   	 double result = 0;
   	 boolean notDone = true;

   	 alreadyVisited[i] = true;

   	 while (notDone) {
   		 for (int j = 0; j < length; j++) {
   			 for (int k = 0; k < length; k++) {
   				 if (j < k
   						 && matrix[j][k] == true
   						 && ((alreadyVisited[j] == true && alreadyVisited[k] == false) || (alreadyVisited[j] == false && alreadyVisited[k] == true))) {
   					 if(newAlreadyVisited[j] != true || newAlreadyVisited[k] != true)
   						 result += (double) noIteration;
   					 newAlreadyVisited[j] = true;
   					 newAlreadyVisited[k] = true;
   				 }
   			 }
   		 }
   		 int count = 0;
   		 for (int j = 0; j < length; j++) {
   			 if (alreadyVisited[j] == true) {
   				 count++;
   			 }
   		 }
   		 if (count == length) {
   			 notDone = false;
   		 }
   		 noIteration++;
   		 for(int j = 0; j < length; j++) {
   			 if(newAlreadyVisited[j] == true) {
   				 alreadyVisited[j] = newAlreadyVisited[j];
   			 }
   		 }
   	 }

   	 result = 1 / result;

   	 return result;
    }

    public static double intermediarite(int i, boolean[][] matrix) {
   	 int length = matrix[0].length;
   	 double result = 0;
   	 boolean notDone = true;
   	 
   	 
   	 /*
   	 for(int j = 0; j < length; j++) {
   		 boolean alreadyVisited[] = new boolean[length];
   		 boolean newAlreadyVisited[] = new boolean[length];
   		 while(notDone) {
   			 for(int k = 0; k < length; k++) {
   				 for(int l = 0; l < length; l++) {
   					 if(k != i && l != i && matrix[k][l] == true && (alreadyVisited[k] == false || alreadyVisited[l] == false)) {
   						 newAlreadyVisited[k] = true;
   						 newAlreadyVisited[l] = true;
   					 }
   				 }
   			 }
   			 alreadyVisited = newAlreadyVisited;
   			 for (int k = 0; k < length; k++) {
   				 if (k != i
   						 && matrix[i][k] == true
   						 && (alreadyVisited[i] == false || alreadyVisited[k] == false)) {
   					 System.out.println(i + " : " + k);
   					 result++;
   					 newAlreadyVisited[i] = true;
   					 newAlreadyVisited[k] = true;4
   				 }
   			 }
   			 int count = 0;
   			 for (int k = 0; k < length; k++) {
   				 if (alreadyVisited[k] == true) {
   					 count++;
   				 }
   			 }
   			 if (count == length) {
   				 notDone = false;
   			 }
   			 alreadyVisited = newAlreadyVisited;
   		 }
   		 notDone = true;
   	 }
   	 */
   	 return result;
    }
}


